import { graphql } from "../graphql";
import type { LoadMeFn, Me, UpdateMeFn } from "./me.types";

export const loadMe: LoadMeFn = async () => {
  const query = `
    query LoadMe {
      me { id nickname createdAt token }
    }
  `;
  const data = await graphql(query);
  return data.me as Me;
};

export const updateMe: UpdateMeFn = async (input) => {
  const query = `
    mutation UpdateMe($input: MeUpdateInput!) {
      meUpdate(input: $input) { id nickname createdAt token }
    }
  `;
  const data = await graphql(query, { input });
  return data.meUpdate as Me;
};
